package com.gzxw.mogublog.admin.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.gzxw.mogublog.commons.entity.Blog;
import com.gzxw.mogublog.commons.entity.PictureSort;
import com.gzxw.mogublog.utils.R;
import com.gzxw.mogublog.xo.service.PictureSortService;
import com.gzxw.mogublog.xo.vo.PictureSortVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/pictureSort")
public class PictureSortController {

    @Autowired
    private PictureSortService pictureSortService;


    @PostMapping("/getList")
    public R getList(@RequestBody PictureSortVO pictureSortVO) {

        IPage<PictureSort> pageList = pictureSortService.getPageList(pictureSortVO);

        Map<String, Object> result = new HashMap<>();
        List<PictureSort> records = pageList.getRecords();
        long total = pageList.getTotal();
        long size = pageList.getSize();
        long current = pageList.getCurrent();
        result.put("records", records);
        result.put("total", total);
        result.put("size", size);
        result.put("current", current);
        return R.success("200", result);
    }




    // 顶置图片类别
    @PostMapping("/stickPictureSort")
    public R stick(@RequestBody PictureSortVO pictureSortVO) {

        String message = pictureSortService.stickPictureSort(pictureSortVO);

        return R.success("200",message);
    }

    @PostMapping("/editPictureSort")
    public R edit(@RequestBody PictureSortVO pictureSortVO) {

        String message = pictureSortService.editPictureSort(pictureSortVO);

        return R.success("200",message);
    }


}
